package com.lepu.app.fun.my;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import lib.share.utils.CallBack;
import lib.share.utils.ShareLib;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.app.application.MyApplication;
import com.app.utils.LoginUtil;
import com.app.utils.MyNetUtil;
import com.app.utils.ObserverConst;
import com.app.utils.SdLocal;
import com.app.utils.Setting;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.ObserverManager;
import com.core.lib.utils.PopUtil;
import com.core.lib.utils.main.DateUtilBase;
import com.core.lib.utils.main.LogUtilBase;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.core.lib.widget.GoogleRefreshLayout;
import com.core.lib.widget.GoogleRefreshLayout.OnLoadListener;
import com.core.lib.widget.MyDialog;
import com.eyzhs.app.R;
import com.lepu.app.fun.grow.bean.HotPhoto;
import com.lepu.app.fun.mother_circle.fragment.FragmentMotherPost;
import com.lepu.app.fun.my.adapter.AdapterImage;
import com.lepu.app.fun.my.adapter.AdapterPubContentComment;
import com.lepu.app.fun.my.bean.BeanCollectKnowledge;
import com.lepu.app.fun.my.bean.BeanPubContent;
import com.lepu.app.fun.my.bean.BeanPubContentComment;
import com.lepu.app.fun.my.bean.BeanPubContentCommentReply;
import com.lepu.app.fun.my.bean.BeanPubContentImage;
import com.lepu.app.fun.my.fragment.FragmentMyTopic;
import com.lepu.app.main.activity.MainTabActivity;
import com.lepu.app.usercenter.bean.LoginInfo;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewRightButtonListener;
import com.lepu.app.widget.ListViewForScrollview;

public class PubContentDetailActivity extends BaseFragmentActivity implements
		AsyncRequest, OnRefreshListener, OnLoadListener,
		OnTopbarNewLeftLayoutListener,OnEditorActionListener {

	private static final String REQUEST_DATA = "request_data";
	private static final String REQUEST_DATA_MORE = "request_data_more";

	private static final String REQUEST_SEND_COMMENT = "request_send_comment";
	private static final String REQUEST_SEND_LIKE = "request_send_like";

	// 我的主题列表，可以删除主题
	private static final String REQUEST_DELETE_TOPIC = "request_delete_topic";

	private static final String REQUEST_TOPIC_DETAIL = "request_topic_detail";
	
	private static final int MSG_DATA_SUCCESS = 10;
	private static final int MSG_DATA_FAIL = 11;
	private static final int MSG_DATA_MORE_SUCCESS = 12;
	private static final int MSG_DATA_MORE_FAIL = 13;

	private static final int MSG_SEND_COMMENT_SUCCESS = 20;
	private static final int MSG_SEND_COMMENT_FAIL = 21;

	private static final int MSG_LIKE_SUCCESS = 30;
	private static final int MSG_LIKE_FAIL = 31;

	private static final int MSG_DATA_GET_SUCCESS = 40;
	private static final int MSG_DATA_GET_FAIL = 41;

	// ========================================================================
	private GoogleRefreshLayout mGoogleRefreshLayout = null;
	private ListView mDataListView = null;
	private AdapterPubContentComment mDataAdapter = null;
	private ArrayList<BeanPubContentComment> mDataArrayList = null;
	private ArrayList<BeanPubContentComment> mHotArrayList = null;
	private int mCurrentPage = 1;

	private BeanPubContent mBeanPubContent;
	private String mTopicID = "";

	private View mLikeView;

	private TextView mCommentTextView;

	private String mCurrentDate = null;

	private CustomTopBarNew mTopbar = null;
	public EditText mContentEditText;
	public LinearLayout mConmentLayout;

	public int mCurrentTag = 0;
	public boolean isReply = false; // 回复/评论
	public String replyId = "-1"; // 回复id
	private int commentId = 0;
	public static PubContentDetailActivity mInstance;
	private boolean mIsMyTopic = false;
	private int mNameType = 0;
	private int mHotCount = 0; //热评个数

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_pub_content_detail_activity);
		mInstance = this;
		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		mInstance = null;
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}

	public static PubContentDetailActivity getInstance() {
		return mInstance;
	}

	/**
	 * 初始化方法
	 */
	@SuppressWarnings("deprecation")
	@SuppressLint({ "InflateParams", "ResourceAsColor", "ClickableViewAccessibility" })
	private void init() {
		Bundle bundle = getIntent().getExtras();
		if (bundle != null && bundle.size() > 0) {
			mTopicID = bundle.getString("TopicId");
			mCurrentTag = bundle.getInt("tag");
			mIsMyTopic = bundle.getBoolean("IsMyTopic", false);
			mNameType = bundle.getInt("nameType");
		}

		// topbar
		mTopbar = (CustomTopBarNew) findViewById(R.id.topbar);
		if (mCurrentTag == 0) {
			mTopbar.setTopbarTitle("详情");
		} else {
			mTopbar.setTopbarTitle("帖子详情");
		}

		mTopbar.setonTopbarNewLeftLayoutListener(this);

		mDataArrayList = new ArrayList<BeanPubContentComment>();
		mHotArrayList = new ArrayList<BeanPubContentComment>();
		
		mDataListView = (ListView) findViewById(R.id.dataListView);
		mGoogleRefreshLayout = (GoogleRefreshLayout) findViewById(R.id.swipeLayout);
		mGoogleRefreshLayout.setOnRefreshListener(this);
		mGoogleRefreshLayout.setOnLoadListener(this);
		mGoogleRefreshLayout.setColorScheme(R.color.color_listview_refresh_1,
				R.color.color_listview_refresh_2,
				R.color.color_listview_refresh_3,
				R.color.color_listview_refresh_4);

		Button sendButton = (Button) findViewById(R.id.sendButton);
		sendButton.setOnClickListener(mViewOnClickListener);

		mConmentLayout = (LinearLayout)findViewById(R.id.commentLayout);
		mContentEditText = (EditText) findViewById(R.id.contentEditText);
		mContentEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(2000) });
		mContentEditText.setOnEditorActionListener(this);

		mDataListView.setOnScrollListener(new OnScrollListener() {
			
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				UtilityBase.closeSoftInput(PubContentDetailActivity.this);
			}
			
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				
			}
		});
		
		mDataListView.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
	            UtilityBase.closeSoftInput(PubContentDetailActivity.this);
				return false;
			}
		});
		
		//mDataListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
		
		mGoogleRefreshLayout.setRefreshing(true);
		requestTopicDetail(mTopicID);
	}

	private void initData() {
		if (mCurrentTag == 1) { // 帖子
			updateTopMotherFun(mBeanPubContent);
		} else if (mCurrentTag == 0) { // 妈妈圈
			updateTopMail(mBeanPubContent);
		}

		mGoogleRefreshLayout.setRefreshing(true);
		request(false);
	}

    //宝妈一起秀
	@SuppressLint("InflateParams")
	public void updateTopMail(final BeanPubContent beanPubContent) {

		View view = LayoutInflater.from(this).inflate(R.layout.mail_fun_detail_top, null);

		CircularImageView accountIconImageView = (CircularImageView) view.findViewById(R.id.accountIconImageView);
		accountIconImageView.setOnClickListener(new MoreOnclickListener(beanPubContent));

		String imageUrl = Setting.getImageUrl(beanPubContent.UserAvatar);
		//UniversalImageLoadTool.disPlay(imageUrl, accountIconImageView,R.drawable.app_ic_default_avatar_64);
		LoginUtil.loadSelfUserImage(this, accountIconImageView, imageUrl);

		TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView);
		TextView timeTextView = (TextView) view.findViewById(R.id.timeTextView);
		TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
		TextView detailTextView = (TextView) view.findViewById(R.id.detailTextView);
	    TextView viewCountTextView = (TextView) view.findViewById(R.id.viewCountTextView);

		//mLikeTextView = (TextView) view.findViewById(R.id.likeCountTextView);
		mLikeView = (TextView) view.findViewById(R.id.likeLayout);
		mLikeView.setOnClickListener(mViewOnClickListener);

		mCommentTextView = (TextView) view.findViewById(R.id.commentCountTextView);
		mCommentTextView.setOnClickListener(mViewOnClickListener);
		
		nameTextView.setText(beanPubContent.UserNickName);
		timeTextView.setText(DateUtilBase.friendly_time(beanPubContent.RecordCreateTime));
		titleTextView.setText(beanPubContent.TopicTitle);
		detailTextView.setText(beanPubContent.TopicDetail);
		viewCountTextView.setText("阅读  "+beanPubContent.ViewCount);
		mCommentTextView.setText("  "+beanPubContent.ReplyCount);

		if (beanPubContent.MediaList != null
				&& beanPubContent.MediaList.size() > 0) {
			ArrayList<BeanPubContentImage> dataList = new ArrayList<BeanPubContentImage>();
			for (int i = 0; i < beanPubContent.MediaList.size(); i++) {
				BeanPubContentImage temp = beanPubContent.MediaList.get(i);
				if (temp.MediaType.equals("1")) {
					dataList.add(temp);
				}
			}

			if (dataList != null && dataList.size() > 0) {
				ListViewForScrollview itemListView = (ListViewForScrollview) view
						.findViewById(R.id.itemListView);
				itemListView.setAdapter(new AdapterImage(this,
						beanPubContent.MediaList));
			}
		}

		//点赞
		((TextView)mLikeView).setText("  "+beanPubContent.FavourCount);
		if(!TextUtils.isEmpty(beanPubContent.HasFavour) && beanPubContent.HasFavour.equals("1"))
		{   mLikeView.setSelected(true);
			
		}else{
			mLikeView.setSelected(false);
		}

		if (mIsMyTopic) {
			// 妈妈圈
			mTopbar.setRightButton(R.drawable.icon_delete);
			mTopbar.setOnTopbarNewRightButtonListener(new OnTopbarNewRightButtonListener() {

				@Override
				public void onTopbarRightButtonSelected() {
					delete();
				}
			});
		}else {
			mTopbar.setRightButton(R.drawable.mother_more_icon);
			mTopbar.setOnTopbarNewRightButtonListener(new OnTopbarNewRightButtonListener() {
				@Override
				public void onTopbarRightButtonSelected() {
					showPopSend(beanPubContent);
				}
			});
		}

		mDataListView.addHeaderView(view);
	}

	/*
	 * 帖子
	 */
	@SuppressLint("InflateParams")
	public void updateTopMotherFun(final BeanPubContent beanPubContent) {

		View view = LayoutInflater.from(this).inflate(
				R.layout.mother_fun_detail_top, null);

		CircularImageView accountIconImageView = (CircularImageView) view
				.findViewById(R.id.accountIconImageView);

		accountIconImageView.setOnClickListener(new MoreOnclickListener(beanPubContent));
		String imageUrl = Setting.getImageUrl(beanPubContent.UserAvatar);

//		UniversalImageLoadTool.disPlay(imageUrl, accountIconImageView,
//				R.drawable.app_ic_default_avatar_64);
		LoginUtil.loadSelfUserImage(this, accountIconImageView, imageUrl);

		TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView);
		TextView timeTextView = (TextView) view.findViewById(R.id.timeTextView);
		ImageView titleImage = (ImageView) view.findViewById(R.id.titleImageView);
		TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
		TextView detailTextView = (TextView) view.findViewById(R.id.detailTextView);
		TextView viewCountTextView = (TextView) view.findViewById(R.id.viewCountTextView);

		mLikeView = (TextView) view.findViewById(R.id.likeLayout);
		mLikeView.setOnClickListener(mViewOnClickListener);

		mCommentTextView = (TextView) view.findViewById(R.id.commentCountTextView);
		mCommentTextView.setOnClickListener(mViewOnClickListener);

		titleTextView.setText(beanPubContent.TopicTitle);
		if(mNameType == 1){ //置顶
			titleImage.setBackgroundResource( R.drawable.mother_topic_top_icon);
		}else if(mNameType == 2){ //精华
			titleImage.setBackgroundResource( R.drawable.mother_topic_cream_icon);
		}
		
		nameTextView.setText(beanPubContent.UserNickName);
		timeTextView.setText(beanPubContent.RecordCreateTime);
		detailTextView.setText(beanPubContent.TopicDetail);
		
		viewCountTextView.setText("阅读  "+beanPubContent.ViewCount);
		mCommentTextView.setText("  "+beanPubContent.ReplyCount);

		//点赞
		((TextView)mLikeView).setText("  "+beanPubContent.FavourCount);
		if(!TextUtils.isEmpty(beanPubContent.HasFavour) && beanPubContent.HasFavour.equals("1"))
		{   mLikeView.setSelected(true);
			
		}else{
			mLikeView.setSelected(false);
		}
		
		if (beanPubContent.MediaList != null
				&& beanPubContent.MediaList.size() > 0) {
			ArrayList<BeanPubContentImage> dataList = new ArrayList<BeanPubContentImage>();
			for (int i = 0; i < beanPubContent.MediaList.size(); i++) {
				BeanPubContentImage temp = beanPubContent.MediaList.get(i);
				if (temp.MediaType.equals("1")) {
					dataList.add(temp);
				}
			}

			if (dataList != null && dataList.size() > 0) {
				ListViewForScrollview itemListView = (ListViewForScrollview) view
						.findViewById(R.id.itemListView);
				itemListView.setAdapter(new AdapterImage(this,
						beanPubContent.MediaList));
			}
		}

		if(!TextUtils.isEmpty(beanPubContent.HasFavour) && beanPubContent.HasFavour.equals("1"))
		{   mLikeView.setSelected(true);
		}else{
			mLikeView.setSelected(false);
		}

		if (mIsMyTopic) {
			//帖子
			addTopBarRight(beanPubContent.TopicTitle,beanPubContent.TopicDetail);
		} else {
			mTopbar.setRightButton(R.drawable.mother_more_icon);
			mTopbar.setOnTopbarNewRightButtonListener(new OnTopbarNewRightButtonListener() {

				@Override
				public void onTopbarRightButtonSelected() {
					//share(beanPubContent.TopicTitle, beanPubContent.TopicDetail);
					showPopSend(beanPubContent);
				}
			});
		}

		mDataListView.addHeaderView(view);
	}

	/*
	 * topbar right
	 */
	@SuppressLint("InflateParams")
	private void addTopBarRight(final String shareTitle,
			final String shareDetail) {

		View view = LayoutInflater.from(this).inflate(
				R.layout.app_topbar_right_content, null);
		ImageButton shareImageButton = (ImageButton) view
				.findViewById(R.id.rightImageButton1);
		ImageButton deleteImageButton = (ImageButton) view
				.findViewById(R.id.rightImageButton2);

		shareImageButton.setImageResource(R.drawable.icon_share);
		deleteImageButton.setImageResource(R.drawable.icon_delete);

		shareImageButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				share(shareTitle, shareDetail);
			}
		});

		deleteImageButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				delete();
			}
		});
		mTopbar.addRightContentLayout(view);
	}

	@SuppressLint("InflateParams")
	public void showPopSend(BeanPubContent beanPub) {
		UtilityBase.closeSoftInput(this);

		View view = LayoutInflater.from(this).inflate(R.layout.mother_detail_more_view, null);
		TextView shareText = (TextView) view.findViewById(R.id.mother_detail_share);
		TextView collecText = (TextView) view.findViewById(R.id.mother_detail_collec);
		TextView repotText = (TextView) view.findViewById(R.id.mother_detail_report);
		TextView cannelText = (TextView) view.findViewById(R.id.mother_detail_cannel);
		
		if(BeanCollectKnowledge.checkCollectItemPost(LoginUtil.getUserId(), beanPub.TopicTitle)){
			collecText.setText("取消收藏");
		}
		
		if(beanPub.UserID.equals(LoginUtil.getUserId())){
			repotText.setText("删除");
			repotText.setOnClickListener(new MoreOnclickListener(beanPub, false));
		}else {
			repotText.setText("举报");
			repotText.setOnClickListener(new MoreOnclickListener(beanPub, true));
		}
		
		shareText.setOnClickListener(new MoreOnclickListener(beanPub));
		collecText.setOnClickListener(new MoreOnclickListener(beanPub));
		cannelText.setOnClickListener(new MoreOnclickListener(beanPub));
		
		PopUtil.getInstance().showPopWindow(this, null, view,Gravity.BOTTOM, null, true);
	}
	
	//妈妈圈举报
	@SuppressLint("InflateParams")
	public void showPopSend2(BeanPubContent beanPub) {
		View view = LayoutInflater.from(this).inflate(R.layout.mother_detail_more_view2, null);
		TextView repotText = (TextView) view.findViewById(R.id.mother_detail_report);
		TextView cannelText = (TextView) view.findViewById(R.id.mother_detail_cannel);
		
		cannelText.setOnClickListener(new MoreOnclickListener(beanPub));
		
		if(beanPub.UserID.equals(LoginUtil.getUserId())){
			repotText.setText("删除");
			repotText.setOnClickListener(new MoreOnclickListener(beanPub, false));
		}else {
			repotText.setText("举报");
			repotText.setOnClickListener(new MoreOnclickListener(beanPub, true));
		}
		
		PopUtil.getInstance().showPopWindow(this, null, view,Gravity.BOTTOM, null, true);
	}
	
	 class MoreOnclickListener implements View.OnClickListener{
		 public BeanPubContent beanPub;
		 public boolean isReport;
		 
		 public MoreOnclickListener(BeanPubContent beanPub){
			 this.beanPub = beanPub;
		 }
		 
		 public MoreOnclickListener(BeanPubContent beanPub, boolean isReport){
			 this.beanPub = beanPub;
			 this.isReport = isReport;
		 }
		 
		 public void onClick(View v) {
			 switch (v.getId()) {
				case R.id.mother_detail_share: //分享
					share(beanPub.TopicTitle, beanPub.TopicDetail);
					PopUtil.getInstance().dismissPopWindow();
					break;
				case R.id.mother_detail_collec: //收藏
					
					boolean flagLogin = MainTabActivity.jumpLogin(PubContentDetailActivity.this);
					
					if(flagLogin){
						return;
					}
					
					if(BeanCollectKnowledge.checkCollectItemPost(LoginUtil.getUserId(), beanPub.TopicTitle)){
						BeanCollectKnowledge.deleteItemPost(LoginUtil.getUserId(), beanPub.TopicTitle);
						UIHelper.showToast(PubContentDetailActivity.this, R.string.collect_cancel);
						PopUtil.getInstance().dismissPopWindow();
					}else{
						BeanCollectKnowledge item = new BeanCollectKnowledge();
						item.Uid = LoginUtil.getUserId();
						item.Time = System.currentTimeMillis();

						item.Type = BeanCollectKnowledge.TYPE_TIEZI;
						item.Title = beanPub.TopicTitle;
						item.SubTitle = beanPub.TopicDetail;
						item.ArticleID = mTopicID;
						BeanCollectKnowledge.insertCollectItem(item);

						UIHelper.showToast(PubContentDetailActivity.this, R.string.collect_success);
						PopUtil.getInstance().dismissPopWindow();
					}
					
					
					break;
				case R.id.mother_detail_report: //举报
                    boolean flagLoginReport = MainTabActivity.jumpLogin(PubContentDetailActivity.this);
					
					if(flagLoginReport){
						return;
					}
					
					if(isReport){
						Intent intent = new Intent(PubContentDetailActivity.this, ReportActivity.class);
						intent.putExtra("reportType", 1);  //1 代表论坛主贴  2代表论坛评论
			            intent.putExtra("reportID", beanPub.TopicID);
			            intent.putExtra("reportName", beanPub.TopicTitle);
			            startActivity(intent,true);
					}else{
						delete();
					}
					
		            PopUtil.getInstance().dismissPopWindow();
					break;
				case R.id.mother_detail_cannel: 
					PopUtil.getInstance().dismissPopWindow();
					break;
				case R.id.accountIconImageView:
					LoginUtil.jumpUserInfo(PubContentDetailActivity.this, beanPub.UserID);
					break;
				default:
					break;
		     }
		 }
	 }
	
	
	View.OnClickListener mViewOnClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {

			boolean flag = MainTabActivity
					.jumpLogin(PubContentDetailActivity.this);
			if (flag) {
				return;
			}

			LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();

			switch (v.getId()) {
			case R.id.sendButton:
				
				sendContent();
				break;
			case R.id.likeLayout:

				String optUrl = "";
				String isLike = mBeanPubContent.HasFavour;
				if (isLike.equals("0")) {
					// 赞
					optUrl = Setting.getFavourTopicUrl();
				} else {
					// 取消赞
					optUrl = Setting.getCancelFavourTopicUrl();
				}

				Map<String, Object> optMap = new HashMap<String, Object>();
				JSONObject json = new JSONObject();
				try {
					json.put("DeviceID", Setting.DEVICEID);
					json.put("ApplicationID", Setting.APPLICATIONID);
					json.put("UserID", loginInfo.UserID);
					json.put("LoginToken", loginInfo.LoginToken);
					json.put("TopicID", mTopicID);
					json.put("QuoteReplyID", replyId);
				} catch (Exception e) {
				} 
				optMap.put("ht", json);

				ApiClient.http_post(optUrl, optMap, null,PubContentDetailActivity.this,REQUEST_SEND_LIKE, true,false);

				break;
			case R.id.commentCountTextView:
				showKeyboard(false, null, 0, "");
				break;
			default:
				break;
			}
		}
	};
	
	private void share(String title, String detail) {

		String imgPath = SdLocal.getAppIconPath(getApplicationContext());
		String shareUrl = "";
		
		if (MyApplication.getInstance().checkIsLogin()) {
			LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
			shareUrl = Setting.getShareTopicUrl()+"userID="+loginInfo.UserID+"&detailID="+mTopicID;
		} else {
			shareUrl = Setting.getShareTopicUrl()+"userID="+"-1"+"&detailID="+mTopicID;
		}
		
		// 调用官方sdk分享，可以各种形式
	    ShareLib.Share(PubContentDetailActivity.this, mBeanPubContent.TopicTitle, mBeanPubContent.TopicDetail,imgPath, shareUrl, false, new CallBack() {
			@Override
			public void callBackSuccess(Object obj) {
				super.callBackSuccess(obj);

				MyNetUtil.getInstance().requestShare(PubContentDetailActivity.this, MyNetUtil.getInstance(), 7, mTopicID);
			}
		});
	}

	private void delete() {
		MyDialog dialog = new MyDialog(this)
				.setMessage("您确认要删除这条内容吗?")
				.setPositiveButton(R.string.app_ok, new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						requestDeleteTopic();
					}
				})
				.setNegativeButton(R.string.app_cancel,
						new View.OnClickListener() {

							@Override
							public void onClick(View v) {
							}
						});

		dialog.create(null);
		dialog.showMyDialog();
	}

	public void request(boolean isMore) {

		String request = "";
		int page = 1;
		if (isMore) {
			request = REQUEST_DATA_MORE;
			page = (mCurrentPage + 1);
		} else {
			mCurrentDate = DateUtilBase.stringFromDate(new Date(),DateUtilBase.DATE_ALL_ALL);
			request = REQUEST_DATA;
			mCurrentPage = page;
		}

		String url = Setting.getReplyListUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();

		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);

			if (MyApplication.getInstance().checkIsLogin()) {
				LoginInfo loginInfo = MyApplication.getInstance()
						.getLoginInfo();
				params.put("UserID", loginInfo.UserID);
			} else {
				params.put("UserID", -1);
			}

			params.put("TopicID", mTopicID);

			params.put("RefreshTime", mCurrentDate);
			params.put("PageIndex", page);
			params.put("PageSize", Setting.PAGE_SIZE);
			params.put("SortBy", 1);
			if (mCurrentTag == 1) {
				params.put("SortDirection", "DESC");
			} else {
				params.put("SortDirection", "DESC");
			}

		} catch (Exception e) {
		}
		map.put("ht", params);

		ApiClient.http_post(url, map, null, this, request, false,false,true);
	}

	public void requestDeleteTopic() {
		String url = Setting.getDeleteTopicUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();

		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);

			LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
			params.put("UserID", loginInfo.UserID);
			params.put("LoginToken", loginInfo.LoginToken);

			params.put("TopicIDList", mTopicID);
		} catch (Exception e) {
		}
		map.put("ht", params);

		showProgressDialog();
		ApiClient.http_post_main(url, map, null, this, REQUEST_DELETE_TOPIC,false);
	}

	public void requestTopicDetail(String topicId) {
		String url = Setting.getMyTopicDetailUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();

		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);
			
			if(MyApplication.getInstance().checkIsLogin())
			{
				LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
				params.put("UserID", loginInfo.UserID);
				params.put("LoginToken", loginInfo.LoginToken);
			}

			params.put("TopicID", topicId);
			params.put("PageSize", 10);
		} catch (Exception e) {
		}
		map.put("ht", params);

		ApiClient.http_post_main(url, map, null, this, REQUEST_TOPIC_DETAIL,
				false,false,true);
	}
	
	private void sendContent()
	{
		boolean flag = MainTabActivity
				.jumpLogin(PubContentDetailActivity.this);
		if (flag) {
			return;
		}

		LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
		
		EditText editText = (EditText) findViewById(R.id.contentEditText);
		String content = editText.getText().toString().trim();
		if (TextUtils.isEmpty(content)) {
			UIHelper.showToast(PubContentDetailActivity.this,
					"亲，请先输入评论内容");
			return;
		}

		String url = Setting.getSubmitReplyUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();
		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);
			params.put("UserID", loginInfo.UserID);
			params.put("LoginToken", loginInfo.LoginToken);
			params.put("TopicID", mTopicID);
			params.put("ReplyContent", content);
			if (isReply) {
				params.put("QuoteReplyID",
						mDataArrayList.get(commentId).ReplyID);
			}
		} catch (Exception e) {
		}
		map.put("ht", params);

		showProgressDialog();
		ApiClient.http_post(url, map, null,
				PubContentDetailActivity.this, REQUEST_SEND_COMMENT,
				true);
	}


	public void showKeyboard(boolean reply, String replyID, int commentID,
			String userName) {
		mContentEditText.requestFocus();
		InputMethodManager inputManager = (InputMethodManager) mContentEditText
				.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		inputManager.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
		isReply = reply;
		replyId = replyID;
		commentId = commentID;

//		if (!reply) {
//			mContentEditText.setHint("回复楼主");
//		} else {
//			mContentEditText.setHint("回复"+ (commentID+1) + "楼");
//		}
		mContentEditText.setHint("回复  "+userName);
	}

	@SuppressLint("HandlerLeak")
	public Handler mHandler = new Handler() {

		@SuppressLint("DefaultLocale")
		public void handleMessage(Message msg) {

			switch (msg.what) {
			case MSG_DATA_SUCCESS:

				@SuppressWarnings("unchecked")
				ArrayList<BeanPubContentComment> dataList = (ArrayList<BeanPubContentComment>) msg.obj;
				if (dataList != null && dataList.size() > 0) {
					mDataArrayList.clear();
					
					mDataArrayList.addAll(mHotArrayList);
					mDataArrayList.addAll(dataList);
				} else {
					// UIHelper.showToast(PubContentDetailActivity.this,
					// R.string.no_data);
				}

				mDataAdapter = new AdapterPubContentComment(PubContentDetailActivity.this, mDataArrayList, mHotCount);
				mDataListView.setAdapter(mDataAdapter);
				mConmentLayout.setVisibility(View.VISIBLE);
				// 更新完后调用该方法结束刷新
				mGoogleRefreshLayout.setRefreshing(false);

				if (mDataArrayList != null && mDataArrayList.size() > 0) {
					if (mDataArrayList.size() < Setting.PAGE_SIZE) {
						mGoogleRefreshLayout.setLoadMoreFinish(true);
					}
				}else{
					mGoogleRefreshLayout.setLoadMoreFinish(true);
				}
				break;
			case MSG_DATA_FAIL:

				// 更新完后调用该方法结束刷新
				mGoogleRefreshLayout.setRefreshing(false);
				break;
			case MSG_DATA_MORE_SUCCESS:

				@SuppressWarnings("unchecked")
				ArrayList<HotPhoto> dataMoreList = (ArrayList<HotPhoto>) msg.obj;
				if (dataMoreList != null && dataMoreList.size() > 0) {
					mDataAdapter.notifyDataSetChanged();

					// 加载更多数据成功，page ++
					mCurrentPage++;
				} else {
					UIHelper.showToast(PubContentDetailActivity.this,R.string.no_data_more);
					mGoogleRefreshLayout.setLoadMoreFinish(true);
				}

				// 加载完后调用该方法
				mGoogleRefreshLayout.setLoading(false);
				break;
			case MSG_DATA_MORE_FAIL:

				// 加载完后调用该方法
				mGoogleRefreshLayout.setLoading(false);
				break;
			case MSG_SEND_COMMENT_SUCCESS:

				hideProgressDialog();

				EditText editText = (EditText) findViewById(R.id.contentEditText);
				editText.setText("");
				editText.setHint("回复楼主");

				BeanPubContentComment comment = (BeanPubContentComment) msg.obj;
				comment.UserAvatar = MyApplication.getInstance().getLoginInfo().Avatar;
				comment.UserNickName = MyApplication.getInstance()
						.getLoginInfo().NickName;// 服务端未返回UserNickName
				comment.FavourCount = "0";
				if (isReply) {
					BeanPubContentCommentReply commentReply = new BeanPubContentCommentReply();
					commentReply.ReplyID = mDataArrayList.get(commentId).ReplyID;
					commentReply.UserNickName = mDataArrayList.get(commentId).UserNickName;
					commentReply.Storey = mDataArrayList.get(commentId).Storey;
					commentReply.ReplyContent = mDataArrayList.get(commentId).ReplyContent;

					comment.QuoteReply = commentReply;
				}
				
				if (mCurrentTag == 0) {
					mDataArrayList.add(mHotCount, comment);
					mDataAdapter.notifyDataSetChanged();
					mDataListView.setSelection(mHotCount);
				} else {

					if (mDataArrayList.size() % Setting.PAGE_SIZE == 0
							&& mDataArrayList.size() != 0) {
						return;
					}

					comment.Storey = String.valueOf(mDataArrayList.size() + 1);
					mDataArrayList.add(mHotCount, comment);
					mDataAdapter.notifyDataSetChanged();
					mDataListView.setSelection(mHotCount);
				}

//				request(false);
				
                if (mCurrentTag == 1) {
					if(	FragmentMotherPost.getInstance() != null){
						FragmentMotherPost.getInstance().request(false);
					}
					
				}
				
				//回复成功后默认为回复楼主
				isReply = false;
				replyId = null;
				commentId = 0;
				break;
			case MSG_SEND_COMMENT_FAIL:

				hideProgressDialog();
				break;
			case MSG_LIKE_SUCCESS:

//				mLikeView.setSelected(!mLikeView.isSelected());
//
//				mLikeTextView.setText(String.valueOf(msg.arg1));
				
				((TextView)mLikeView).setText("  "+String.valueOf(msg.arg1));

//				if (mCurrentTag == 0) {
					// 宝宝秀
					if(mBeanPubContent.HasFavour.equals("1")){
						mBeanPubContent.HasFavour = "0";
						mLikeView.setSelected(false);
					}else if(mBeanPubContent.HasFavour.equals("0")){
						mBeanPubContent.HasFavour = "1";
						mLikeView.setSelected(true);
					}
					
					String key1 = String.format("%s_%d", ObserverConst.NOTIFY_MOTHER_POST_CHANGE,1);
					String key2 = String.format("%s_%d", ObserverConst.NOTIFY_MOTHER_POST_CHANGE,2);
					String key3 = String.format("%s_%d", ObserverConst.NOTIFY_MOTHER_POST_CHANGE,3);
					
					 ObserverManager.getInstance().notify(key1, null, null);
					 ObserverManager.getInstance().notify(key2, null, null);
					 ObserverManager.getInstance().notify(key3, null, null);
//				} else if (mCurrentTag == 1) {
					// 帖子
			
//				}
				break;
			case MSG_LIKE_FAIL:
				hideProgressDialog();
				break;
			case MSG_DATA_GET_SUCCESS:
				initData();
				break;
			case MSG_DATA_GET_FAIL:
				hideProgressDialog();
				break;
			default:
				break;
			}
		};
	};

	@Override
	public void onLoad() {
		
		if(mBeanPubContent != null && !TextUtils.isEmpty(mBeanPubContent.UserID))
		{
			request(true);
		}else{
			//详情获取失败，重新获取
			requestTopicDetail(mTopicID);
		}
	}

	@Override
	public void onRefresh() {
		
		if(mBeanPubContent != null && !TextUtils.isEmpty(mBeanPubContent.UserID))
		{
			request(false);
		}else{
			//详情获取失败，重新获取
			requestTopicDetail(mTopicID);
		}
	}

	@Override
	public void RequestComplete(Object object, Object data) {
		if (object.equals(REQUEST_DATA)) {
			// 解析json data
			ArrayList<BeanPubContentComment> dataArraylist = BeanPubContentComment
					.parseJsonData((String) data);

			Message msg = mHandler.obtainMessage();
			msg.what = MSG_DATA_SUCCESS;
			msg.obj = dataArraylist;
			mHandler.sendMessage(msg);
		} else if (object.equals(REQUEST_DATA_MORE)) {
			// 解析json data more
			ArrayList<BeanPubContentComment> dataMoreArraylist = BeanPubContentComment
					.parseJsonData((String) data);

			if (dataMoreArraylist != null && dataMoreArraylist.size() > 0) {
				for (int i = 0; i < dataMoreArraylist.size(); i++) {
					BeanPubContentComment item = dataMoreArraylist.get(i);
					mDataArrayList.add(item);
				}
			}

			Message msg = mHandler.obtainMessage();
			msg.what = MSG_DATA_MORE_SUCCESS;
			msg.obj = dataMoreArraylist;
			mHandler.sendMessage(msg);
		} else if (object.equals(REQUEST_SEND_COMMENT)) {

			BeanPubContentComment comment = BeanPubContentComment
					.parseJsonSimpleData((String) data);

			if (comment != null) {
				Message commentMsg = mHandler.obtainMessage();
				commentMsg.obj = comment;
				commentMsg.what = MSG_SEND_COMMENT_SUCCESS;
				mHandler.sendMessage(commentMsg);
			} else {
				mHandler.sendEmptyMessage(MSG_SEND_COMMENT_FAIL);
			}

		} else if (object.equals(REQUEST_SEND_LIKE)) {
			String result = (String) data;
			int code = 0;
			int count = 0;
			try {
				JSONObject jsonObject = new JSONObject(result);
				JSONObject obj1 = (JSONObject) jsonObject.get("Result");
				code = obj1.optInt("Status");

				JSONObject obj2 = (JSONObject) obj1.get("DetailInfo");
				count = obj2.optInt("FavourCount");
			} catch (JSONException e) {
				e.printStackTrace();
			}

			if (code == 200) {
				Message msg = mHandler.obtainMessage();
				msg.what = MSG_LIKE_SUCCESS;
				msg.arg1 = count;
				mHandler.sendMessage(msg);
			} else {
				mHandler.sendEmptyMessage(MSG_LIKE_FAIL);
			}
		} else if (object.equals(REQUEST_DELETE_TOPIC)) {
			// main thread
			hideProgressDialog();

			FragmentMyTopic fragmentInstance = FragmentMyTopic.getInstance();
			if(fragmentInstance != null)
			{
				fragmentInstance.deleteIndex();
			}

			finish(true);
		} else if (object.equals(REQUEST_TOPIC_DETAIL)) {
			LogUtilBase.LogD(null, "获取详情成功");

			mGoogleRefreshLayout.setRefreshing(false);
			
			mBeanPubContent = BeanPubContent.parseJson((String) data);
			ArrayList<BeanPubContentComment> dataArraylist = BeanPubContentComment.parseJsonHotData((String) data);
			if(dataArraylist != null){
				//热评
				mHotArrayList = dataArraylist;
				mHotCount = dataArraylist.size();
				mDataArrayList.addAll(mHotArrayList);
			}
			
			Message msg = mHandler.obtainMessage();
			msg.what = MSG_DATA_GET_SUCCESS;
			mHandler.sendMessage(msg);
		}
	}

	@Override
	public void RequestError(Object object, int errorId, String errorMessage) {
		if (object.equals(REQUEST_DATA)) {
			mHandler.sendEmptyMessage(MSG_DATA_FAIL);
		} else if (object.equals(REQUEST_DATA_MORE)) {
			mHandler.sendEmptyMessage(MSG_DATA_MORE_FAIL);
		} else if (object.equals(REQUEST_SEND_COMMENT)) {
			mHandler.sendEmptyMessage(MSG_SEND_COMMENT_FAIL);
		} else if (object.equals(REQUEST_SEND_LIKE)) {
			mHandler.sendEmptyMessage(MSG_LIKE_FAIL);
		} else if (object.equals(REQUEST_DELETE_TOPIC)) {
			// main thread

			hideProgressDialog();
		} else if (object.equals(REQUEST_TOPIC_DETAIL)) {
			mGoogleRefreshLayout.setRefreshing(false);
		}
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}
	
	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		switch (actionId) {
		case EditorInfo.IME_ACTION_SEND:
			
			sendContent();
			break;
		}
		return false;
	}

}
